<template>
    <div> 
         <canvas id="q"></canvas>
         <br/>
          <el-button type="success" @click="exportData" icon="el-icon-download"> 导出数据</el-button>
          <br/>
          <el-form >
           <el-form-item>
                <el-upload
                :show-file-list="false"
                :before-upload="beforeUpload"
                :on-success="onSuccess"
                :on-error="onError"
                :disabled="importDataDisabled"
                style="display: inline-flex;margin-right: 8px"
                :action="uploadUrl"
                >
                <el-button
                    :disabled="importDataDisabled"
                    type="success"
                    :icon="importDataBtnIcon"
                >{{importDataBtnText}}</el-button>
                </el-upload>
            </el-form-item>
          </el-form>
         
    </div>

</template>
<script>
export default {
   data() {
    return {
      importDataBtnText: "导入数据",
      importDataBtnIcon: "el-icon-upload2",
      importDataDisabled: false,
      uploadUrl:"http://localhost:9999/biz/tGoods/updateLoad?access_token=",
      form: {
        name: ""
      }
    };

    },methods:{
        exportData() {
        var url = "http://localhost:9999/biz/tGoods/downLoadGoodsExcel?pageNo=1&pageSize=10&access_token="+localStorage.getItem("access_token");
         window.open(url, "_parent");
    },
     beforeUpload() {
      this.importDataBtnText = "正在导入";
      this.importDataBtnIcon = "el-icon-loading";
      this.importDataDisabled = true;
    },
    onSuccess(response, file, fileList) {
      this.importDataBtnText = "导入数据";
      this.importDataBtnIcon = "el-icon-upload2";
      this.importDataDisabled = false;
      //this.initEmps();
    },
    onError(err, file, fileList) {
      this.importDataBtnText = "导入数据";
      this.importDataBtnIcon = "el-icon-upload2";
      this.importDataDisabled = false;
    }
    },
    mounted() {
        this.uploadUrl = this.uploadUrl+localStorage.getItem("access_token");



    var canvas = document.getElementById("q");
    var $this = this;
    this.axios({
        method:'get',
        url: "http://localhost:9999/biz/alibaba/pay",
        params: {
            orderNo:new Date().getTime(),
            "access_token":localStorage.getItem("access_token")
        }
    }).then(function(res){
            console.log(res);

        console.log(res.data.obj);
         $this.QRCode.toCanvas(
             canvas,
            res.data.obj,
      function(error) {
        if (error) {
          console.error(error);
        }
        console.log("QRCode success!");
      }
    );
    })
   
  },
}
</script>